package cn.lsnu.heritage.controller;

import cn.lsnu.heritage.common.Result;
import cn.lsnu.heritage.model.domain.Category;
import cn.lsnu.heritage.model.dto.Top9Dto;
import cn.lsnu.heritage.service.CategoryService;
import cn.lsnu.heritage.service.IcHeritageService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("category")
public class CategoryController {

    @Resource
    private IcHeritageService icHeritageService;
    @Resource
    private CategoryService categoryService;

    //查询分类集合
    @GetMapping("queryCategoryList")
    public Result<List<Category>> queryCategoryList(){
        return Result.success(categoryService.list());
    }

    @GetMapping("/queryHotCategoryList")
    public Result<List<Top9Dto>> queryHotCategoryList(){
        List list = null;
        try {
            list = icHeritageService.queryHotCategoryList();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("60000","糟糕了非遗被遗忘了");
        }
        return Result.success(list);
    }
}
